// import pako from 'pako';
const decoder = new TextDecoder('utf-8');

var LgxCompressTool = {}

LgxCompressTool.compresse2Base64Str = function(origdata) {
    // const base64String = btoa(origdata);
    const base64String = btoa(unescape(encodeURIComponent(origdata)));
    const decodedUint8Array = Uint8Array.from(atob(base64String), c => c.charCodeAt(0));
    const compressedData = pako.deflate(decodedUint8Array, { to: 'string' });
    const compressedBase64String = btoa(
        Array.from(compressedData).reduce((acc, byte) => acc + String.fromCharCode(byte), '')
      );
      
    return compressedBase64String;
}

LgxCompressTool.deCompresseBase64Str = function(compressBaseStr) {
    const compressedUint8Array = Uint8Array.from(atob(compressBaseStr), c => c.charCodeAt(0));

    // 使用 pako 进行解压缩
    const decompressedUint8Array = pako.inflate(compressedUint8Array);

    // 将解压缩后的 Uint8Array 转换为字符串
    const decompressedString = decoder.decode(decompressedUint8Array);
    return decompressedString;
}

export {LgxCompressTool}
